package com.mochat.logger.impl;


import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import com.mochat.api.logger.LoggerRemoteServiceI;
import com.mochat.model.RandomMessageBody;
import com.mochat.model.RoomMessageBody;
import com.mongodb.DBObject;

/*@Service("logRemoteService")*/
public class LoggerRemoteService implements LoggerRemoteServiceI{

	@Autowired
	private MongoTemplate mongoTemplate;
	
	@Override
	public void insertLogger(String loggerStr) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void insertRandomLogger(RandomMessageBody randomMessageBody) {
		// TODO Auto-generated method stub
		try {
			DBObject dbObject = com.mochat.utils.BeanUtil.bean2DBObject(randomMessageBody);
			Date date = new Date();
			dbObject.put("time", date);
			dbObject.put("type", "random");
			mongoTemplate.save(dbObject, "mochat_log");
		} catch (IllegalArgumentException | IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}

	@Override
	public void insertRoomLogger(RoomMessageBody roomMessageBody) {
		// TODO Auto-generated method stub
		try {
			DBObject dbObject = com.mochat.utils.BeanUtil.bean2DBObject(roomMessageBody);
			dbObject.put("type", "room");
			Date date = new Date();
			dbObject.put("time", date);
			mongoTemplate.save(dbObject, "mochat_log");
		} catch (IllegalArgumentException | IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
}
